package com.minarto.display {
	import com.minarto.ui.KeyboardManager;
	import com.minarto.tooltip.ToolTipManager;
	import flash.ui.Mouse;
	import scaleform.clik.data.DataBinding;
	import scaleform.clik.core.CLIK;
	import flash.display.*;
	import flash.events.*;
	import scaleform.gfx.Extensions;
	
	
	public function documentInit($main:Sprite, $afterInit:Function=null, ...$afterInitArgs):void {
		$main.addEventListener(Event.ADDED_TO_STAGE, function($e:Event):void {
				var st:Stage;
			
				$main.removeEventListener($e.type, arguments.callee);
				st = $main.stage;
				
				if (st === $main.parent) {
					Extensions.enabled = true;
					
					st.align = StageAlign.TOP_LEFT;
					st.scaleMode = StageScaleMode.NO_SCALE;
					
					if (Extensions.isScaleform) {
						st.tabEnabled = false;
					}
					
					DataBinding.initialize();
					Mouse.hide();
					CLIK.stage = st;
					
					ToolTipManager.init(st);
					KeyboardManager.init(st);
				}
				
				if (Boolean($afterInit)) {
					$afterInit.apply(null, $afterInitArgs);
				}
			}, false, 0, true);
	}
}